﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.BusinessLogic.Money;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Orm.Model;
using OpenSoftStore.Orm.View;

namespace OpenSoftStore.Client.UIL.ManageMember
{
    public partial class DinnerSaleBackWindow : Form
    {
        public DinnerSaleLogic LgcDinnerSale;
        public V_DinnerSale VdinnerSale ;
        public List<T_Dinner> Tdinners;
        public DinnerLogic LgcDinner;
        public DinnerSaleBackWindow()
        {
            InitializeComponent();
            LgcDinnerSale=new DinnerSaleLogic();
            VdinnerSale=new V_DinnerSale();
            LgcDinner=new DinnerLogic();
            Tdinners = LgcDinner.GetDinners();
            cmbDinnerId.DataSource = Tdinners;
            cmbDinnerId.DisplayMember = "Name";
            cmbDinnerId.ValueMember = "Id";

            var moenyLogic = new MoneyLogic();
            var moenyList = moenyLogic.SqlWhere<T_Account>(" 1=1").ToList();
            var list = moenyList.Where(m => m.Name != "现金").ToList();
            cmbBankAccountId.DataSource = list;
            cmbBankAccountId.DisplayMember = "Name";
            cmbBankAccountId.ValueMember = "Id";

        }

        public void SetDinnerSale(string id)
        {
            string where = string.Format(" where T_DinnerSale.Id = '{0}'", id);
            VdinnerSale = LgcDinnerSale.GetDinnerSaleObject(where);
            VdinnerSale.MemberCardId += "  "+VdinnerSale.MemberName;
            SPACommon.SetObjectToControlValue(this, VdinnerSale);
        }

        private void pbClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnSave_Click(object sender, EventArgs e)
        {
            VdinnerSale.CashCancelPay = nudCashPay.Value;
            VdinnerSale.BankAccountIdCancel = cmbBankAccountId.SelectedValue.ToString();
            VdinnerSale.BankCancelPay = nudBankPay.Value;
            VdinnerSale.ValueCancelPay = nudValuePay.Value;
            int row = LgcDinnerSale.Back(VdinnerSale);
            if (row > 0)
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
    }
}
